package com.song.EMS.wx.controller;

import com.song.EMS.bean.Courier;
import com.song.EMS.bean.Message;
import com.song.EMS.mvc.ResponseBody;
import com.song.EMS.service.impl.CourierServiceImpl;
import com.song.EMS.utils.JsonUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

public class CourierController {
    private CourierServiceImpl courierService = new CourierServiceImpl();
    /**
     * 获取所有快递员处理快递的数量排行
     * @param request
     * @param response
     * @return
     */
    @ResponseBody("/wx/lazytotal.do")
     public String getTotalLazy(HttpServletRequest request, HttpServletResponse response){
        Message data = null;
        HashMap<String, List> map = new HashMap<>();
        List<Courier> lazyCouriers = courierService.getLazyCouriers(null);
        List<Courier> hardworkingCouriers = courierService.getHardworkingCouriers(null);
        if (lazyCouriers.size() > 0 &&hardworkingCouriers.size() > 0){
            map.put("lazy",lazyCouriers);
            map.put("hardworking",hardworkingCouriers);
            data = new Message(1,null,map);
        }else{
            data = new Message(0,"没有查询到信息");
        }
        return JsonUtil.toJSON(data);

    }

    /**
     * 获取当年所有快递员处理快递的数量排行
     * @param request
     * @return
     */
    @ResponseBody("/wx/lazyYear.do")
     public String getYearlyLazy(HttpServletRequest request, HttpServletResponse response){
        Message data = null;
        HashMap<String, List> map = new HashMap<>();
        List<Courier> lazyCouriers = courierService.getLazyCouriers("%y");
        List<Courier> hardworkingCouriers = courierService.getHardworkingCouriers("%y");
        if (lazyCouriers.size() > 0 &&hardworkingCouriers.size() > 0){
            map.put("lazy",lazyCouriers);
            map.put("hardworking",hardworkingCouriers);
            data = new Message(1,null,map);
        }else{
            data = new Message(0,"没有查询到信息");
        }
        return JsonUtil.toJSON(data);

     }

    /**
     * 获取当月所有快递员处理快递的数量排行
     * @param request
     * @param response
     * @return
     */
    @ResponseBody("/wx/lazyMonth.do")
     public String getMonthlyLazy(HttpServletRequest request, HttpServletResponse response){
        Message data = null;
        HashMap<String, List> map = new HashMap<>();
        List<Courier> lazyCouriers = courierService.getLazyCouriers("%m");
        List<Courier> hardworkingCouriers = courierService.getHardworkingCouriers("%m");
        if (lazyCouriers.size() > 0 &&hardworkingCouriers.size() > 0){
            map.put("lazy",lazyCouriers);
            map.put("hardworking",hardworkingCouriers);
            data = new Message(1,null,map);
        }else{
            data = new Message(0,"没有查询到信息");
        }
        return JsonUtil.toJSON(data);

     }
}
